#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int T,n,m,V,L,p[MAXN],t,sum,sum2;
int G[22][22],ton[22];
struct car{
    int d,v,a;
    double mxd,mnd;
}c[MAXN];
int cmp(car a,car b){
    if(a.mnd==b.mnd){
        return a.mxd<b.mxd;
    }
    return a.mnd<b.mnd;
}
void dfs(int now,int z){
    int ton2[22];
    if(now==m+1){
        int x=0;
        for(int i=1;i<=n;i++){
            x+=ton[i];
        }
        if(x==sum){
            sum2=max(m-z,sum2);
        }
        return;
    }
    dfs(now+1,z);
    for(int i=1;i<=n;i++){
        ton2[i]=ton[i];
    }
    for(int i=1;i<=n;i++){
        if(G[i][now]==1){
            ton[i]=1;
        }
    }
    dfs(now+1,z+1);
    for(int i=1;i<=n;i++){
        ton[i]=ton2[i];
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&n,&m,&L,&V);
        t=1;
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
            if(c[i].a<0){
                t=0;
            }
            if(c[i].a>0){
                if(c[i].v>V){
                    c[i].mnd=c[i].d;
                    c[i].mxd=L;
                    //c[i].k=1;
                }else{
                    if(2*c[i].a*(L-c[i].d)+c[i].v*c[i].v<V*V){
                        c[i].mnd=-1;
                        c[i].mxd=-1;
                    }else{
                        c[i].mnd=((V*V-c[i].v*c[i].v)*1.0)/(2.0*c[i].a)+double(c[i].d)+0.0000001;
                        c[i].mxd=L;
                        //c[i].k=3;
                    }
                }
            }else if(c[i].a<0){
                if(c[i].v<=V){
                    c[i].mnd=-1;
                    c[i].mxd=-1;
                }else{
                    c[i].mnd=c[i].d;
                    c[i].mxd=((c[i].v*c[i].v)*1.0-V*V)/(2.0*(-1*c[i].a))+double(c[i].d)-0.0000001;
                    //c[i].k=2;
                }
            }else{
                if(c[i].v>V){
                    c[i].mnd=c[i].d;
                    c[i].mxd=L;
                    //c[i].k=1;
                }else{
                    c[i].mnd=-1;
                    c[i].mxd=-1;
                }
            }
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
        }

        //cout<<t;
        if(t==1){
            int ans=0,ans2=0;
            for(int i=1;i<=n;i++){
                if(p[m]>=c[i].mnd&&c[i].mnd!=-1){
                    ans++;
                }
            }
            if(ans!=0) ans2=m-1;
            else ans2=m;
            printf("%d %d\n",ans,ans2);
            continue;
        }
        if(n<=20&&m<=20){
            sum=0;
            sum2=-1;
            memset(G,0,sizeof(G));
            for(int i=1;i<=n;i++){
                int f=0;
                for(int j=1;j<=m;j++){
                    if(c[i].mnd<=p[j]&&c[i].mxd>=p[j]){
                        f=1;
                        G[i][j]=1;
                    }
                }
                sum+=f;
            }
            dfs(1,0);
            printf("%d %d\n",sum,sum2);
        }

    }

    return 0;
}
